#include <iostream>
#include <string>
#include <cmath>

bool is_prime(int num) {
    if (num < 2) {
        return false;
    }
    for (int i = 2; i <= sqrt(num); i++) {
        if (num % i == 0) {
            return false;
        }
    }
    return true;
}

int closest_prime_number(int num) {
    if (is_prime(num)) {
        return num;
    }
    int lower = num - 1;
    int upper = num + 1;
    while (true) {
        if (is_prime(lower)) {
            return lower;
        } else if (is_prime(upper)) {
            return upper;
        }
        lower--;
        upper++;
    }
}

int main() {
    std::string input_words[3];
    std::cin >> input_words[0] >> input_words[1] >> input_words[2];
    
    std::string number_str = "";
    for (const std::string& word : input_words) {
        if (word == "zero") {
            number_str += "0";
        } else if (word == "one") {
            number_str += "1";
        } else if (word == "two") {
            number_str += "2";
        } else if (word == "three") {
            number_str += "3";
        } else if (word == "four") {
            number_str += "4";
        } else if (word == "five") {
            number_str += "5";
        } else if (word == "six") {
            number_str += "6";
        } else if (word == "seven") {
            number_str += "7";
        } else if (word == "eight") {
            number_str += "8";
        } else if (word == "nine") {
            number_str += "9";
        }
    }
    
    if (number_str.length() != 3) {
        std::cout << "Wrong input" << std::endl;
    } else {
        int number = std::stoi(number_str);
        int result = closest_prime_number(number);
        std::cout << result << std::endl;
    }
}